//<---------------------孙梦海增加------------------>

//<---------------------孙梦海增加------------------>
var images;
var selectID = "";
var selected = '';
var beforechange = '';
var toolImages = "";
var catchesImages = "";
var fatherID = ""; //记录采样水层的ID，在toolAndFish中调用

//<---------------------黄文海增加------------------>
//这三个变量在toolAndFish中用来记录调用下一页的ID;
var WLEID1;
var WLEID2;
var WLEID3;
var WLEID4;
var idPNT; //记录选中的PNT，在addWLE中需要利用其添加采样水层;
var selectWLE;
var choosed;
//<---------------------黄文海增加------------------>

function hideAllButton() {
    $("#update-data").hide();
    $("#add-child-node1").hide();
    $("#add-child-node").hide();
    $("#delete-node").hide();
}


$(document).ready(function () {
    var height = $(document).height();
    var width = $(document).width();
    var realheight = height - 100;
    $("#article").height(realheight).width(width - 150);
    $("#mapinfo").height(height - 500);
//点击按钮1后
    $("#key").click(function () {
        var left = width - 660 + "px";
        //alert(left);
        $("#search").width("500px").css({"position": "absolute", "left": left, "top": "100px"});
        $("#map").width(width - 660).height(height - 100);
        $("#key").css({"display": "none"});
        $("#key2").css({"display": "block"});
    });
    //点击按钮2后
    $("#key2").click(function () {
        $("#map").width(0).height(0);
        $("#search").width("100%").css({"position": "absolute", "left": "0", "top": "100px"});
        $("#key").css({"display": "block"});
        $("#key2").css({"display": "none"});
    });
    //黄文海 获取子节点信息
    function getData(text) {

        fatherID = text;
        var tr = ["a", "b", "c", "d", "e"];
        var wd = ["wa", "wb", "wc", "wd", "we"];
        $("#catchesTable button").each(function (i, n) {
            $(this).css({"display": "none"});
        });
        $("#detectionTable button").each(function (i, n) {
            $(this).css({"display": "none"});
        });

        for (var j = 0; j < 5; j++) {
            $("#" + tr[j] + " td").each(function (i, n) {
                if (i > 4) return;
                $(this).html("");
            });
            $("#" + wd[j] + " td").each(function (i, n) {
                if (i > 3) return;
                $(this).html("");
            });
            $("#" + wd[j]).hide();
            $("#" + tr[j]).hide();
        }
        $("#toolTable").css({"display": "none"});
        /*获取网具,水质,渔获物信息*/
        $.ajax({
            type: "get",
            async: true,
            url: "AllMonit.action?monitID=" + text,
            success: function (result) {
                if (result == "00") {
                    alert("发生错误，请稍后再试！");
                    return;
                } else if (result == "" || result == null) {

                } else {
                    var nodeArray = result.split(",");
                    var catchesCount = 0;
                    for (var j = 0; j < nodeArray.length; j++) {
                        var select = tr[j];
                        if (nodeArray[j].substring(0, 3) == "CTH"){
                            catchesCount++;
                            $.ajax({
                                type: "get",
                                url: "ShowMessage.action?monitID=" + nodeArray[j],
                                async: false,
                                success: function (result) {
                                    var Mon0 = result.split(",");
                                    $("#" + select).show();
                                    $("#" + select + " td").each(function (i, n) {
                                        if (i >= 6) return;
                                        if (i == 0 || i == 1) {
                                            $(this).html(Mon0[i]);
                                            return;
                                        }
                                        if (i == 5) {
                                            if (Mon0[2].length == 0) {
                                                catchesImages = [];
                                            } else catchesImages = Mon0[2].split("|");
                                            return;
                                        }
                                        $(this).html(Mon0[i + 1]);
                                    });
                                    $("#" + select + " button").each(function (i, n) {
                                        if (userName == "privilege" && $(this).text() == "添加") {
                                            return;
                                        }
                                        $(this).css({"display": "inline-block"});
                                    });
                                }
                            });
                        }else if(nodeArray[j].substring(0, 3) == "WDD"){
                            var selectID = wd[j - catchesCount];
                            $.ajax({
                                type: "get",
                                url: "ShowMessage.action?monitID=" + nodeArray[j],
                                async: false,
                                success: function (result) {
                                    var Mon1 = result.split(",");
                                    $("#" + selectID).show();
                                    $("#" + selectID + " td").each(function (i, n) {
                                        if (i > 3) return;
                                        $(this).html(Mon1[i]);
                                    });
                                    $("#" + selectID + " button").each(function (i, n) {
                                        if (userName == "privilege" && $(this).text() == "添加") {
                                            return;
                                        }
                                        $(this).css({"display": "inline-block"});
                                    });
                                }
                            });
                        }else {
                            break;
                        }
                    }

                    var Mon = nodeArray[nodeArray.length - 1];
                    if (Mon.substring(0, 3) == "CTH") return;
                    $.ajax({
                        type: "get",
                        url: "ShowMessage.action?monitID=" + Mon,
                        async: true,
                        success: function (result) {
                            var Mon1 = result.split(",");
                            $("#addTool").css({"display": "none"});
                            $("#toolTable").show();
                            $("#toolTable td").each(function (i, n) {

                                if (i > 8) return;
                                if (i == 0 || i == 1) {
                                    $(this).html(Mon1[i]);
                                    return;
                                }
                                if (i == 8) {
                                    if (Mon1[2].length == 0) {
                                        toolImages = [];
                                    } else toolImages = Mon1[2].split("|");
                                    return;
                                }
                                if (i == 5 || i == 6) {
                                    $(this).html(Mon1[i + 1].substring(0, 8));
                                    return;
                                }
                                $(this).html(Mon1[i + 1]);
                            });
                        }

                    });
                }
            }
        });
    }

    //结束

    var tree = $('#tree');

    function createTree(initTree) {
        tree.jstree({
            'core': {
                "check_callback": true,
                'data': [{
                    "id": "jh",
                    "text": "监测点列表",
                    "icon": "fa fa-th-list",
                    "state": "open",
                    "children": initTree
                }],
            },
            "checkbox": {
                "keep_selected_style":true
            },
            'strings': {'Loading ...': 'Please wait ...'},
            "types": {
                "default": {
                    "icon": "fa fa-bank",
                },
            },
            "plugins": ["types"]
        }).bind("changed.jstree", function (e, data) {//用户单击树节点时候触发
            //被选中的节点编号
            selected = data.selected;
            choosed = data;
            if (data.selected.length === 1 ) {
                $("#delete-node").html("删除本节点");
                $("#add-child-node").show();
            } else {
                $("#delete-node").html("删除这些节点");
                $("#add-child-node").hide();
            }
            var selnode = data.instance.get_node(selected);
            var text1 = tree.jstree().get_text(selected);
            if (text1 == false) return;
            var text;
            if (text1.substring(0, 3) == "监测点" && text1 != "监测点列表") {
                text = tree.jstree().get_node(selected).id;
                selectID = text;
            }
            else if (text1.substring(0, 2) == "断面") {
                text = tree.jstree().get_node(selected).id;
            }
            else if (text1.substring(0, 2) == "测线" || text1.substring(0, 2) == "测点") {
                text = text1.substring(3, text1.length);
            }
            else if (text1.substring(0, 4) == "采样水层" || text1.substring(0, 4) == "混合采样") {
                if (text1.substring(0, 4) == "采样水层")
                    text = text1.substring(6, text1.length);
                else
                    text = text1.substring(5, text1.length);
            } else {
                text = text1;
            }
            $("#addWLE").hide();
            if (text == "监测点列表") {
                $("#add-child-node1").hide();
                $("#add-feature").hide();
                $("#add-child-node").html("<span class='glyphicon glyphicon-plus'></span>&nbsp" + "添加监测点");
                if (userName == "privilege") {
                    hideAllButton();
                }
            } else if (text.substring(0, 3) == "MON") {
                $("#add-child-node1").hide();
                $("#add-feature").hide();
                $("#add-child-node").html("<span class='glyphicon glyphicon-plus'></span>&nbsp" + "添加断面");
            } else if (text.substring(0, 3) == "SEC") {
                $("#add-feature").hide();
                $("#add-child-node").html("<span class='glyphicon glyphicon-plus'></span>&nbsp" + "添加测线");
                $("#add-child-node1").show();
            } else if (text.substring(0, 3) == "LIN") {
                $("#add-child-node1").hide();
                $("#add-feature").hide();
                $("#add-child-node").html("<span class='glyphicon glyphicon-plus'></span>&nbsp" + "添加测点");
            }
            else if (text.substring(0, 3) == "PNT") {
                idPNT = text;
                $("#add-child-node1").hide();
                $("#add-feature").hide();
                $("#addWLE").show();   ///黄文海
            } else {
                $("#FishEggsDiv").hide();
                $("#fishesDiv").hide();
                $("#update-data").hide();  //确认修改按钮

            }


            $("#node-text").html("已选中:<small><i>" + text1 + "</i></small>");

            //<---------------------孙梦海增加------------------>
            //点击查看显示优势种
            $("#pfeature-node").click(function () {
                $("#pfeature-table").show();
            });
            //<---------------------孙梦海增加------------------>

            if (beforechange != selected.toString() || selected != "jh") {
                //清除前一次验证的错误信息
                $("#monitsite_check").data('validator').resetForm();
                $("#surface_check").data('validator').resetForm();
                if (selected == "jh") {
                    $("#tree-menu").css({"display": "block"});
                    $("#input-place").css({"display": "none"});
                    $("#update-data").css({"display": "none"});  //确认修改按钮
                    $("#add-monitsite input").each(function () {
                        $(this).val("");
                    });
                    beforechange = selected;
                    return;
                } else {
                    var MonitArr = [];


                    $("#input-place").css({"display": "block"});
                    $("#update-data").css({"display": "block"});
                    $("#monitsiteButton").css({"display": "none"});
                    $("#add-child-node").css({"display": "inline-block"});
                    $("#delete-node").css({"display": "inline-block"});
                    $.ajax({
                        type: "get",
                        url: "ShowMessage.action?monitID=" + text,
                        async: true,
                        success: function (result) {
                            MonitArr = result.split(',');

                            if (text.substring(0, 3) == "MON") {
                                $("#monitsiteButton").css({"display": "inline-block"});
                                $("#add-surface input").each(function () {
                                    $(this).val("");
                                });
                                $("#Weather1").val(MonitArr[13]);
                                var mypcas = new PCAS("province", "city", "area", MonitArr[4].split("-")[0], MonitArr[4].split("-")[1], MonitArr[4].split("-")[2]);

                                $("#add-monitsite input").each(function (i, n) {
                                    if (i <= 2) {
                                        $(this).val(MonitArr[i + 1]);
                                        return;
                                    }
                                    if (i == 11) {
                                        $(this).val(MonitArr[14]);
                                        return;
                                    }

                                    if (i == 12) {
                                        if (MonitArr[4].split("-")[3] == undefined) {
                                            $(this).val(MonitArr[4])
                                        }
                                        else {
                                            $(this).val(MonitArr[4].split("-")[3]);
                                        }
                                        return;
                                    }
                                    if (i == 4) {
                                        $(this).after($(this).clone().val(""));
                                        $(this).remove();
                                        if (MonitArr[i + 2].length == 0) {
                                            images = [];
                                        } else images = MonitArr[i + 2].split("|");
                                        return;
                                    }
                                    $(this).val(MonitArr[i + 2]);
                                });
                                //<---------------------孙梦海增加------------------>
                                //隐藏断面下面的浮游生物、底栖生物表格
                                $(".surface").hide();
                                //<---------------------孙梦海增加------------------>

                                $("#add-monitsite").css({"display": "block"});
                                $("#add-surface").css({"display": "none"});
                                $("#add-line").css({"display": "none"});
                                $("#add-water").css({"display": "none"});
                                $("#add-Dot").css({"display": "none"});
                                $("#add-child-sub").css({"display": "none"});
                            } else if (text.substring(0, 3) == "SEC") {
                                $("#add-surface input").each(function () {
                                    $(this).val("");
                                });
                                $("#selectSurface").val(MonitArr[1]);
                                $("#add-surface input").each(function (i, n) {
                                    $(this).val(MonitArr[i + 2]);
                                });

                                //<---------------------孙梦海增加------------------>
                                //清除动态生成的表格
                                $("#sed-fea  tr:not(:first)").remove();
                                //隐藏浮游生物、底栖生物优势种表格
                                $("#pfeature-table").hide();
                                //显示断面下面的浮游生物、底栖生物表格
                                $(".surface").show();
                                //<---------------------孙梦海增加------------------>
                                $("#add-monitsite").css({"display": "none"});
                                $("#add-surface").css({"display": "block"});
                                $("#add-line").css({"display": "none"});
                                $("#add-Dot").css({"display": "none"});
                                $("#add-water").css({"display": "none"});
                                $("#add-child-sub").css({"display": "none"});

                                //<---------------------孙梦海增加------------------>
                                //异步刷新显示断面下面的列表
                                $.ajax({
                                    type: "get",
                                    async: true,
                                    url: "query_next_dot.action?monitID=" + text,
                                    success: function (result) {
                                        if (result == "01") {
                                            alert("往后索引有待开发！");
                                            return;
                                        } else if (result == "00") {
                                            alert("发生错误，请稍后再试！")
                                            return;
                                        } else if (result == "" || result == null) {

                                        } else {
                                            MonitArr = result.split(',');
                                            var str;
                                            for (var ix = 0; ix < MonitArr.length; ix++) {
//									  alert(MonitArr[ix]);
                                                if (MonitArr[ix].substring(0, 3) == "SED") {

                                                    str = "沉积物:";
                                                    //调用显示函数
                                                    $.showSed(str, MonitArr[ix]);
                                                }

                                                else if (MonitArr[ix].substring(0, 3) == "ZOO") {
                                                    var str1 = "浮游动物:";
                                                    //调用显示函数
                                                    $.showFea(str1, MonitArr[ix]);

                                                } else if (MonitArr[ix].substring(0, 3) == "PHY") {
                                                    var str2 = "浮游植物:";
                                                    //调用显示函数
                                                    $.showFea(str2, MonitArr[ix]);

                                                } else if (MonitArr[ix].substring(0, 3) == "BEN") {
                                                    var str3 = "底栖生物:";
                                                    //调用显示函数
                                                    $.showFea(str3, MonitArr[ix]);

                                                }

                                            }
                                        }

                                    }
                                });
                                //<---------------------孙梦海增加------------------>
                            } else if (text.substring(0, 3) == "LIN") {
                                $("#add-line input").each(function () {
                                    $(this).val("");
                                });
                                $("#add-line input").each(function (i, n) {
                                    $(this).val(MonitArr[i + 1]);

                                });
                                //隐藏断面下面的浮游生物、底栖生物表格
                                $(".surface").hide();

                                $("#add-monitsite").css({"display": "none"});
                                $("#add-surface").css({"display": "none"});
                                $("#add-line").css({"display": "block"});
                                $("#add-Dot").css({"display": "none"});
                                $("#add-water").css({"display": "none"});
                                $("#add-child-sub").css({"display": "none"});
                            } else if (text.substring(0, 3) == "PNT") {
                                $("#add-Dot input").each(function () {
                                    $(this).val("");
                                });
                                var dataArray = result.split("_");
                                MonitArr = dataArray[0].split(",");

                                $("#add-Dot input").each(function (i, n) {
                                    $(this).val(MonitArr[i + 1]);

                                });
                                $("#WLEupper").hide();
                                $("#WLEmiddle").hide();
                                $("#WLElow").hide();
                                $("#WLEmix").hide();
                                if (userName != "privilege") {
                                    $("#addWLEupper").show();
                                    $("#addWLEmiddle").show();
                                    $("#addWLElow").show();
                                    $("#addWLEmix").show();
                                }
                                for (var k = 1; k < dataArray.length; k++) {
                                    MonitArr = dataArray[k].split(",");
                                    if (MonitArr[1] == "上") {
                                        WLEID1 = MonitArr[0];
                                        $("#addWLEupper").css({"display": "none"});
                                        $("#WLEupper").show();
                                        $("#WLEupper td").each(function (i, n) {
                                            if (i > 3) return;
                                            $(this).html(MonitArr[i + 2]);
                                        });
                                    } else if (MonitArr[1] == "中") {
                                        WLEID2 = MonitArr[0];
                                        $("#addWLEmiddle").css({"display": "none"});
                                        $("#WLEmiddle").show();
                                        $("#WLEmiddle td").each(function (i, n) {
                                            if (i > 3) return;
                                            $(this).html(MonitArr[i + 2]);
                                        });
                                    } else if (MonitArr[1] == "下") {
                                        WLEID3 = MonitArr[0];
                                        $("#addWLElow").css({"display": "none"});
                                        $("#WLElow").show();
                                        $("#WLElow td").each(function (i, n) {
                                            if (i > 3) return;
                                            $(this).html(MonitArr[i + 2]);
                                        });
                                    } else {
                                        WLEID4 = MonitArr[0];
                                        $("#addWLEmix").css({"display": "none"});
                                        $("#WLEmix").show();
                                        $("#WLEmix td").each(function (i, n) {
                                            if (i > 3) return;
                                            $(this).html(MonitArr[i + 2]);
                                        });
                                    }
                                }
                                //隐藏断面下面的浮游生物、底栖生物表格
                                $(".surface").hide();

                                $("#add-monitsite").css({"display": "none"});
                                $("#add-surface").css({"display": "none"});
                                $("#add-line").css({"display": "none"});
                                $("#add-Dot").css({"display": "block"});
                                $("#add-water").css({"display": "none"});
                                $("#add-child-sub").css({"display": "none"});
                                $("#add-child-node").css({"display": "none"});

                            }
                            else {
                                $("#update-data").hide();
                                $(".hand").hide();
                                //黄文海
                                $("#add-water input").each(function () {
                                    $(this).val("");
                                });
                                if (MonitArr[1] != "混")
                                    $("#selectWater").val(MonitArr[1]);
                                else
                                    $("#selectWater").val("混合");

                                $("#add-water input").each(function (i, n) {
                                    $(this).val(MonitArr[i + 2]);

                                });
                                if (userName != "privilege") {
                                    $("#addTool").css({"display": "inline-block"});
                                }
                                getData(text);
                                //记录当前显示采样水层的ＩＤ值；，在ｔｏｏｌａｎｄＦｉｓｈ中利用到
                                selectWLE = text;
                                //隐藏断面下面的浮游生物、底栖生物表格
                                $(".surface").hide();

                                $("#add-monitsite").css({"display": "none"});
                                $("#add-surface").css({"display": "none"});
                                $("#add-line").css({"display": "none"});
                                $("#add-Dot").css({"display": "none"});
                                $("#add-water").css({"display": "block"});
                                $("#add-child-sub").css({"display": "none"});
                                $("#add-child-node").css({"display": "none"});
                                //huang
                            }
                        }
                    });
                    beforechange = selected;
                }
                //修改监测信息
                $("#update-data,.update-data").unbind("click").bind("click", function () {
//				  alert(text);
                    if (text.substring(0, 3) == "MON") {
                        //修改监测点
                        var formData = new FormData($("#monitsite_check")[0]);
                        var url = "op_monsite.action";
                        formData.append("flag", "update");
                        formData.append("InverstigationID", text);
                        formData.append("Site", $("#province").find("option:selected").text() + "-" + $("#city").find("option:selected").text() + "-" + $("#area").find("option:selected").text() + "-" + $("#Site1").val());
                        if ($("#Photo1").val().length > 100 || $("#Photo1").val().length <= 0) formData.append("isNull", "");
                        else formData.append("isNull", "有");
                        $.ajax({
                            url: url,
                            type: 'POST',
                            data: formData,
                            async: true,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success: function (result) {
                                if (result == "error") {
                                    alert("修改失败！");
                                } else if (result == "null") {
                                    alert("请填写必填项！");
                                } else {
                                    tree.jstree().set_text(selected, "监测点:" + $("#River1").val() + " " + $("#Site1").val() + " " + text.substring(3, 11));
                                    tree.jstree().open_node(selected);
                                    images = result.split("|");
                                    alert("修改成功！");

                                }
                            }

                        });


                    } else if (text.substring(0, 3) == "SEC") {
                        //修改断面
                        $.ajax({
                            type: "post",
                            async: true,
                            url: "op_frasur.action",
                            data: {
                                "flag": "update",
                                "ID": text,								//主键
                                "Position": $("#selectSurface option:selected").text(),
                                "Distance2Bank": $("#Distance2Bank2").val()
                            },
                            success: function (result) {
                                if (result == "error") {
                                    alert("修改失败！");
                                } else {
                                    //$("#input-place").css({"display":"none"});
                                    tree.jstree().set_text(selected, "断面:" + $("#selectSurface option:selected").text());
                                    tree.jstree().open_node(selected);
                                    alert("修改成功！");

                                }
                            }
                        });
                    } else if (text.substring(0, 3) == "LIN") {				//修改测线
                        $.ajax({
                            type: "post",
                            async: true,
                            url: "op_mealin.action",
                            data: {
                                "flag": "update",
                                "ID": text,						//主键
                                "StartLongitude": $("#StartLongitude3").val(),
                                "StartLatitude": $("#StartLatitude3").val(),
                                "EndLongitude": $("#EndLongitude3").val(),
                                "EndLatitude": $("#EndLatitude3").val()
                            },
                            success: function (result) {
                                if (result == "error") {
                                    alert("修改失败！");
                                } else {
                                    //$("#input-place").css({"display":"none"});
                                    alert("修改成功！");

                                }
                            }
                        });

                    } else if (text.substring(0, 3) == "PNT") {				//修改测点
                        $.ajax({
                            type: "post",
                            async: true,
                            url: "op_meapoi.action",
                            data: {
                                "flag": "update",
                                "ID": text,							//主键
                                "Longitude": $("#LongitudeDot").val(),
                                "Latitude": $("#LatitudeDot").val(),
                            },
                            success: function (result) {
                                if (result == "error") {
                                    alert("修改失败！");
                                } else {
                                    //$("#input-place").css({"display":"none"});
                                    alert("修改成功！");

                                }
                            }
                        });
                    }
                    else {
                        $.ajax({									//修改采样水层
                            type: "post",
                            async: true,
                            url: "op_watlay.action",
                            data: {
                                "flag": "update",
                                "ID": text,						//主键
                                "Layer": $("#selectWater option:selected").text(),
                                "Depth": $("#Depath").val(),
                                "Temperature": $("#waterWarm").val(),
                                "WaterLevel": $("#waterHeight").val(),
                                "Velocity": $("#waterFlow").val()
                            },
                            success: function (result) {
                                if (result == "error") {
                                    alert("修改失败！");
                                } else {
                                    //$("#input-place").css({"display":"none"});
                                    alert("修改成功！");

                                }
                            }
                        });

                    }
                });
                if (userName == "privilege") {
                    hideAllButton();
                }
            }


            $("#rename-place").css({"display": "none"});
            $("#tree-menu").css({"display": "block"});

            var test = tree.jstree().get_json();

            var MonitArr = [];

            tree.unbind("dblclick.jstree").bind("dblclick.jstree", function (obj) {
                //双击展开节点，再次双击关闭节点
                if (tree.jstree().is_open(selected)) {
                    tree.jstree().close_node(selected);
                }
                else {
                    tree.jstree().open_node(selected);
                    if (!data.instance.is_leaf(selnode)) return;
//				  隐藏图片上传,显示查看照片按钮
                    $("#tag").hide();

                    $("#input-place").css({"display": "block"});
                    $("#monitsiteButton").css({"display": "none"});
                    if (selected == 'jh') {
//					  alert(selected);
                        $.ajax({
                            type: "get",
                            async: true,
                            url: "AllMonit.action?monitID=jjhh",
                            success: function (result) {
                                MonitArr = result.split(',');
                                if (result.length != 0) {
                                    for (var ix = 0; ix < MonitArr.length; ix++) {
//								  alert(MonitArr[ix]);
                                        $.ajax({
                                            type: "get",
                                            url: "ShowMessage.action?monitID=" + MonitArr[ix],
                                            async: true,
                                            success: function (result) {
                                                MonitArrCon = result.split(',');
                                                var siteName;
                                                if (MonitArrCon[4].split("-")[3] === undefined) {
                                                    siteName = MonitArrCon[4];
                                                } else {
                                                    siteName = MonitArrCon[4].split("-")[3]
                                                }
                                                tree.jstree().create_node(selected,
                                                    {
                                                        "id": MonitArrCon[0],
                                                        "text": "监测点:" + MonitArrCon[5] + " " + siteName + " " + MonitArrCon[0].substring(3, 11),
                                                        "icon": "fa fa-bank",
                                                    }, "last");
                                                /*if(tree.jstree().is_closed(selected)){tree.jstree().open_node(selected);}
                                                 if(tree.jstree().is_closed(selected)){tree.jstree().open_node(selected);}*/
                                                tree.jstree().open_node(selected);
                                            }

                                        });

                                    }
                                }
                                // if(result.length!=0)
//							  tree.jstree().open_node(selected);
                            }
                        });
                    } else {
                        $.ajax({


                            type: "get",
                            async: true,
                            url: "AllMonit.action?monitID=" + text,
                            success: function (result) {
                                if (result == "00") {
                                    alert("发生错误，请稍后再试！");
                                    return;
                                } else if (result == "" || result == null) {
                                    alert("往后已无索引！");
                                } else {

                                    MonitArr = result.split(',');
                                    var str, icon;
                                    if (text.substring(0, 3) == "MON") {
                                        str = "断面:";
                                        icon = "fa fa-area-chart";
                                        for (var ix = 0; ix < MonitArr.length; ix++) {
                                            $.ajax({
                                                type: "get",
                                                url: "ShowMessage.action?monitID=" + MonitArr[ix],
                                                async: true,
                                                success: function (result) {
                                                    MonitArrCon = result.split(',');
                                                    tree.jstree().create_node(selected,
                                                        {
                                                            "id": MonitArrCon[0],
                                                            "text": "断面:" + MonitArrCon[1],
                                                            "icon": icon,
                                                        }, "last");
                                                    tree.jstree().open_node(selected);
                                                }
                                            });
                                        }
                                    }
                                    else {
                                        if (text.substring(0, 3) == "SEC") {
                                            str = "测线:";
                                            icon = "fa fa-bar-chart-o";
                                        }
                                        else if (text.substring(0, 3) == "LIN") {
                                            str = "测点:";
                                            icon = "fa fa-dot-circle-o";
                                        }
                                        else if (text.substring(0, 3) == "PNT") {
                                            str = "采样水层";
                                            icon = "fa fa-circle-o";
                                        }
                                        else if (text.substring(0, 3) == "WLE") return;
                                        var te;
                                        for (var ix = 0; ix < MonitArr.length; ix++) {
                                            if (str == "采样水层") {
                                                if (MonitArr[ix].substr(0, 1) == "混") {
                                                    te = "混合采样" + MonitArr[ix].substr(1);
                                                }
                                                else te = str + MonitArr[ix];

                                            }
                                            else {
                                                te = str + MonitArr[ix];
                                            }
                                            tree.jstree().create_node(selected,
                                                {
                                                    "id": MonitArr[ix],
                                                    "text": te,
                                                    "icon": icon,
                                                }, "last");
                                        }
                                        tree.jstree().open_node(selected);
                                    }
                                }
                            }
                        });
                    }
                }

            });
        });

    }
    
    function multiDelete() {
        var s2 = choosed.selected[0].substring(0,3);
        var allSelectedData = "";
        for (var i=0; i<choosed.selected.length; i++) {
            var s1 = choosed.selected[i].substring(0,3);
            allSelectedData = allSelectedData + choosed.selected[i];
            if (s1 !== s2) {
                alert("不能同时删除不同类型的节点!");
                return;
            }
        }
        $.ajax({
            type:"get",
            async:true,
            url:"DeleteMonit.action?monitID=" + allSelectedData,
            success: function (result) {
                if (result === "error") {
                    alert("删除失败，请稍后再试！");
                    window.location.reload();
                } else if (result === "success") {
                    alert("删除成功！");
                    window.location.reload();
                }
            }
        });
    }

    //设置标志变量，搜索后的分页数据不一样
    var flag = 0;
    var pageNumber;
    var allPages;
    var searchData;//筛选后的所有监测点

    //监测点搜索
    $("#showSearch").click(function () {
        $(".search-box").slideDown("slow");
    });

    $("#hiddenSearch").click(function () {
        $(".search-box").slideUp("slow");
    });

    $("#search").click(function () {
        $.ajax({
            type: "post",
            async: false,
            url: "SearchMonitSite.action",
            data: {
                "River": $("#search-river").val(),
                "Site": $("#search-site").val(),
                "InvestigationDate": $("#search-date").val(),
            },
            success: function (result) {
                if (result == "none") {
                    alert("未搜索到相关监测点");
                } else if (result == "error") {
                    alert("搜索失败");
                } else {

                    $("#search-river").val("");
                    $("#search-site").val("");
                    $("#search-date").val("");

                    searchData = result;
                    var MonitArr = result.split(',');
                    //筛选过后总数据是MonitArr
                    //标志现在是筛选后，将页码置1，重新计算总页数
                    flag = 1;
                    pageNumber = 1;
                    //获取总页数
                    allPages = Math.ceil(MonitArr.length / 18);
                    $("#all").text(allPages);

                    //删除整棵树
                    tree.jstree().destroy();
                    //重新生成并载入树
                    search_treeCreate(pageNumber);

                }
            }
        });
        return false;
    });
    //筛选树节点后的分页函数
    function search_treeCreate(pageNumber) {
        var MonitArr = [];
        $.ajax({
            type: "post",
            async: true,
            url: "SearchPage.action",
            data: {
                "searchData": searchData,
                "pageNumber": pageNumber,
            },
            success: function (result) {
                MonitArr = result.split(',');
                var initTree = new Array(MonitArr.length);
                for (var i = 0; i < MonitArr.length; i++) {
                    var d = {};
                    $.ajax({
                        type: "get",
                        url: "ShowMessage.action?monitID=" + MonitArr[i],
                        async: true,
                        success: function (result) {
                            MonitArrCon = result.split(',');
//									  alert(MonitArrCon);
                            var siteName;
                            if (MonitArrCon[4].split("-")[3] === undefined) {
                                siteName = MonitArrCon[4];
                            } else {
                                siteName = MonitArrCon[4].split("-")[3]
                            }
                            d["text"] = "监测点:" + MonitArrCon[5] + " " + siteName + " " + MonitArrCon[0].substring(3, 11);
                            d["id"] = MonitArrCon[0];
                            d["state"] = "open";
                            initTree[i] = d;
                        }
                    });
                }
                createTree(initTree);
                return true;
            }
        });


        //树加载完成后触发事件，默认展开第一层节点
        tree.on("loaded.jstree", function (e, data) {
            $.ajax({
                type: "post",
                async: true,
                url: "SearchPage.action",
                data: {
                    "searchData": searchData,
                    "pageNumber": pageNumber,
                },
                success: function (result) {

                    MonitArr = result.split(',');
                    if (result.length != 0) {
                        $(".treePage").show();
                        for (var ix = 0; ix < MonitArr.length; ix++) {
//								  alert(MonitArr[ix]);
                            $.ajax({
                                type: "get",
                                url: "ShowMessage.action?monitID=" + MonitArr[ix],
                                async: true,
                                success: function (result) {

                                    MonitArrCon = result.split(',');
                                    var siteName;
                                    if (MonitArrCon[4].split("-")[3] === undefined) {
                                        siteName = MonitArrCon[4];
                                    } else {
                                        siteName = MonitArrCon[4].split("-")[3]
                                    }
                                    tree.jstree().create_node("jh",
                                        {
                                            "id": MonitArrCon[0],
                                            "text": "监测点:" + MonitArrCon[5] + " " + siteName + " " + MonitArrCon[0].substring(3, 11),
                                            "icon": "fa fa-bank",
                                        }, "last");
                                    tree.jstree().open_node(selected);

                                    //默认展开树的第一层节点
                                    //自动触发一次单击树节点事件
                                    $(tree.jstree().select_node(MonitArr[0])).click();
                                }

                            });

                        }
                    }
                    else {
                        $(".treePage").hide();
                    }
                    // if(result.length!=0)
//							  tree.jstree().open_node(selected);
                }
            });
        });
    }

    //一般的树分页函数
    function treeCreate(pageNumber) {
        var MonitArr = [];
        $.ajax({
            type: "get",
            async: true,
            url: "QueryMonitSite.action",
            data: {
                "pageNumber": pageNumber,
            },
            success: function (result) {
                if (result == "error") {
                    $(".treePage").hide();
                    alert("后台无数据，您可添加数据");
                    var nullTree = [];
                    createTree(nullTree);
                    return;
                } else if (result == "NO Right!") {
                    $(".treePage").hide();
                    alert("你没有权利操作监测点！");
                    return;
                }

                var MonitArr = result.split(',');
                var initTree = new Array(MonitArr.length);
                for (var i = 0; i < MonitArr.length; i++) {
                    var d = {};
                    $.ajax({
                        type: "get",
                        url: "ShowMessage.action?monitID=" + MonitArr[i],
                        async: true,
                        success: function (result) {
                            MonitArrCon = result.split(',');
//								  alert(MonitArrCon);
                            var siteName;
                            if (MonitArrCon[4].split("-")[3] === undefined) {
                                siteName = MonitArrCon[4];
                            } else {
                                siteName = MonitArrCon[4].split("-")[3]
                            }
                            d["text"] = "监测点:" + MonitArrCon[5] + " " + siteName + " " + MonitArrCon[0].substring(3, 11);
                            d["id"] = MonitArrCon[0];
                            d["state"] = "open";
                            initTree[i] = d;
                        }
                    });
                }
                createTree(initTree);
                return true;
            }
        });


        //树加载完成后触发事件，默认展开第一层节点
        tree.on("loaded.jstree", function (e, data) {
            $.ajax({
                type: "get",
                async: true,
                data: {
                    "pageNumber": pageNumber,
                },
                url: "AllMonit.action?monitID=jjhh",
                success: function (result) {

                    MonitArr = result.split(',');
                    if (result.length != 0) {
                        $(".treePage").show();
                        for (var ix = 0; ix < MonitArr.length; ix++) {
//							  alert(MonitArr[ix]);
                            $.ajax({
                                type: "get",
                                url: "ShowMessage.action?monitID=" + MonitArr[ix],
                                async: true,
                                success: function (result) {

                                    MonitArrCon = result.split(',');
                                    var siteName;
                                    if (MonitArrCon[4].split("-")[3] === undefined) {
                                        siteName = MonitArrCon[4];
                                    } else {
                                        siteName = MonitArrCon[4].split("-")[3]
                                    }
                                    tree.jstree().create_node("jh",
                                        {
                                            "id": MonitArrCon[0],
                                            "text": "监测点:" + MonitArrCon[5] + " " + siteName + " " + MonitArrCon[0].substring(3, 11),
                                            "icon": "fa fa-bank",
                                        }, "last");
                                    tree.jstree().open_node(selected);

                                    //默认展开树的第一层节点
                                    //自动触发一次单击树节点事件
                                    $(tree.jstree().select_node(MonitArr[0])).click();
                                }

                            });

                        }
                    }
                    else {
                        $(".treePage").hide();
                    }
                    // if(result.length!=0)
//						  tree.jstree().open_node(selected);
                }
            });
        });
    }

    //获取总页数
    $.ajax({
        type: "get",
        async: false,
        url: "GetAllMonit.action",
        success: function (result) {
            allPages = Math.ceil(result / 18);
        }
    });
    $("#all").text(allPages);
    //页号
    pageNumber = 1;
    treeCreate(pageNumber);
    //树节点上一页
    $("#prePage").click(function () {
        if (pageNumber == 1) {
            alert("这是首页，没有上一页");
        } else {
            //删除整棵树
            tree.jstree().destroy();
            //重新生成并载入树;
            if (flag) {
                search_treeCreate(--pageNumber);
            } else {
                treeCreate(--pageNumber);
            }
        }
    });
    //树节点下一页
    $("#nexPage").click(function () {
        if (pageNumber == allPages) {
            alert("这是尾页，没有下一页");
        } else {
            //删除整棵树
            tree.jstree("destroy");

            //重新生成并载入树
            if (flag) {
                search_treeCreate(++pageNumber);
            } else {
                treeCreate(++pageNumber);
            }

        }
    });
    //树节点首页
    $("#firstPage").click(function () {
        //删除整棵树
        tree.jstree("destroy");
        //重新生成并载入树
        pageNumber = 1;
        if (flag) {
            search_treeCreate(pageNumber);
        } else {
            treeCreate(pageNumber);
        }
    });
    //树节尾页
    $("#lastPage").click(function () {
        //删除整棵树
        tree.jstree("destroy");
        //重新生成并载入树
        pageNumber = allPages;
        if (flag) {
            search_treeCreate(pageNumber);
        } else {
            treeCreate(pageNumber);
        }
    });
    //跳转到某一页
    $("#page").keyup(function (event) {
        if (event.keyCode == 13) {
            var reg = /^[0-9]*[1-9][0-9]*$/;
            inputPage = $("#page").val();
            if (!reg.test(inputPage) || inputPage > allPages) {
                alert("请输入1至" + allPages + "内的正整数");
            } else {
                //删除整棵树
                tree.jstree("destroy");
                //重新生成并载入树
                pageNumber = inputPage;
                if (flag) {
                    search_treeCreate(pageNumber);
                } else {
                    treeCreate(pageNumber);
                }
            }
            $("#page").val("");
        }
    });


//<---------------------孙梦海增加------------------>
    $(".close").unbind("click").bind("click", function () {
        $(".modal").hide();
    });
//修改
    $(".table").on("click", ".update", function () { //动态生成的按钮需要用on()方法
        $(".submit").hide();
        $(".alter").show();
        var info = $(this).parent();
        var text1 = $(this).parent().siblings(".name").text();
        var text;
        if (text1.substring(0, 3) == "沉积物") {
            text = text1.substring(4, text1.length);
            $(".title").text("修改沉积物信息");
            $("#modal-sediment").show();
        }
        else if (text1.substring(0, 4) == "浮游动物" || text1.substring(0, 4) == "浮游植物" || text1.substring(0, 4) == "底栖生物") {
            text = text1.substring(5, text1.length);
            $(".title").text("修改" + text1.substring(0, 4) + "信息");
            $("#modal-feature").show();

            //弹出框显示原具体信息
            $("#feature-Biomass").val(info.siblings("td:eq(1)").text());
            $("#feature-Quality").val(info.siblings("td:eq(2)").text());

        }
        else if (text1.substring(0, 6) == "优势浮游动物" || text1.substring(0, 6) == "优势浮游植物" || text1.substring(0, 6) == "优势底栖生物") {
            text = text1.substring(7, text1.length);
            $(".title").text("修改" + text1.substring(0, 6) + "信息");
            $("#modal-pfeature").show();

            //弹出框显示原具体信息
            $("#pfeature-Name").val(info.siblings("td:eq(1)").text());
            $("#pfeature-Biomass").val(info.siblings("td:eq(2)").text());
            $("#pfeature-Quality").val(info.siblings("td:eq(3)").text());
        }

        $(".alter").unbind("click").bind("click", function () {
            if (text.substring(0, 3) == "SED") {
                var formData = new FormData($("#form-sediment")[0]);
                //alert(formData);
                var url = "UpdateSediment.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#sediment-Photo").val().length > 100 || $("#sediment-Photo").val().length <= 0) formData.append("isNull", "");
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else {
                            alert("修改成功！");
                            $(".modal").hide();
                        }
                    }
                });
            } else if (text.substring(0, 3) == "ZOO") {			//修改浮游动物信息
                var formData = new FormData($("#feature_check")[0]);
                var url = "UpdateZooPlankton.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#feature-Photo").val().length > 100 || $("#feature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else {
                            alert("修改成功！");
                            //更改成功后隐藏弹出框并更新表格内容
                            $(".modal").hide();
                            info.siblings("td:eq(1)").text($("#feature-Biomass").val());
                            info.siblings("td:eq(2)").text($("#feature-Quality").val());
                        }
                    }
                });
            }
            else if (text.substring(0, 3) == "PHY") {				//修改浮游植物信息
                var formData = new FormData($("#feature_check")[0]);
                var url = "UpdatePhytoPlankton.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#feature-Photo").val().length > 100 || $("#feature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else {
                            alert("修改成功！");
                            //更改成功后隐藏弹出框并更新表格内容
                            $(".modal").hide();
                            info.siblings("td:eq(1)").text($("#feature-Biomass").val());
                            info.siblings("td:eq(2)").text($("#feature-Quality").val());
                        }
                    }
                });
            }
            else if (text.substring(0, 3) == "BEN") {			//修改底栖生物信息
                var formData = new FormData($("#feature_check")[0]);
                var url = "UpdateBenthos.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#feature-Photo").val().length > 100 || $("#feature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else {
                            alert("修改成功！");
                            //更改成功后隐藏弹出框并更新表格内容
                            $(".modal").hide();
                            info.siblings("td:eq(1)").text($("#feature-Biomass").val());
                            info.siblings("td:eq(2)").text($("#feature-Quality").val());
                        }
                    }
                });
            }
            else if (text.substring(0, 3) == "PZO") {			//修改浮游动物优势种信息

                var formData = new FormData($("#pfeature_check")[0]);
                var url = "UpdateDominantZooplanktonSpecies.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#pfeature-Photo").val().length > 100 || $("#pfeature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else if (result == "null") {
                            alert("请填写必填项！");
                        } else {
                            alert("修改成功！");
                            //更改成功后隐藏弹出框并更新表格内容
                            $(".modal").hide();
                            info.siblings("td:eq(1)").text($("#pfeature-Name").val());
                            info.siblings("td:eq(3)").text($("#pfeature-Quality").val());
                            info.siblings("td:eq(2)").text($("#pfeature-Biomass").val());
                        }
                    }
                });
            }
            else if (text.substring(0, 3) == "PPH") {				//修改浮游植物优势种信息
                var formData = new FormData($("#pfeature_check")[0]);
                var url = "UpdateDominantPhytoplanktonSpecies.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#pfeature-Photo").val().length > 100 || $("#pfeature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else if (result == "null") {
                            alert("请填写必填项！");
                        } else {
                            alert("修改成功！");
                            //更改成功后隐藏弹出框并更新表格内容
                            $(".modal").hide();
                            info.siblings("td:eq(1)").text($("#pfeature-Name").val());
                            info.siblings("td:eq(3)").text($("#pfeature-Quality").val());
                            info.siblings("td:eq(2)").text($("#pfeature-Biomass").val());
                        }
                    }
                });
            }
            else if (text.substring(0, 3) == "PBE") {				//修改底栖生物优势种信息
                var formData = new FormData($("#pfeature_check")[0]);
                var url = "UpdateDominantBenthosSpecies.action";
                formData.append("flag", "update");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#pfeature-Photo").val().length > 100 || $("#pfeature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("修改失败！");
                        } else if (result == "null") {
                            alert("请填写必填项！");
                        } else {
                            alert("修改成功！");
                            //更改成功后隐藏弹出框并更新表格内容
                            $(".modal").hide();
                            info.siblings("td:eq(1)").text($("#pfeature-Name").val());
                            info.siblings("td:eq(3)").text($("#pfeature-Quality").val());
                            info.siblings("td:eq(2)").text($("#pfeature-Biomass").val());
                        }
                    }
                });
            }
        });
    });
//删除
    $("#sed-fea").on("click", ".delete", function () { //动态生成的按钮需要用on()方法
        if (confirm("您确定删除该条数据吗？")) {
            var index = $("#sed-fea tr").index($(this).parent().parent());
            var text1 = $(this).parent().siblings(".name").text();
            var text;
            if (text1.substring(0, 3) == "沉积物") {
                text = text1.substring(4, text1.length);
            }
            else if (text1.substring(0, 4) == "浮游动物" || text1.substring(0, 4) == "浮游植物" || text1.substring(0, 4) == "底栖生物") {
                text = text1.substring(5, text1.length);
            }
            else if (text1.substring(0, 6) == "优势浮游动物" || text1.substring(0, 6) == "优势浮游植物" || text1.substring(0, 6) == "优势底栖生物") {
                text = text1.substring(7, text1.length);
            }
            $.ajax({
                type: "get",
                async: true,
                url: "DeleteMonit.action?monitID=" + text,
                success: function (result) {
                    if (result == "isnull") {
                        alert("删除失败，请检查数据库是否有该数据！");
                        return false;
                    } else if (result == "error") {
                        alert("删除失败，请稍后再试！");
                        return false;
                    } else if (result == "success") {
                        alert("删除成功！");
                        //删除表格行及优势种表格
                        $("#sed-fea tr").eq(index).remove();
                        $("#pfeature-table").hide();
                    }
                }
            });
        }
    });
    $("#pfea").on("click", ".delete", function () { //动态生成的按钮需要用on()方法
        if (confirm("您确定删除该条数据吗？")) {
            var index = $("#pfea tr").index($(this).parent().parent());
            var text1 = $(this).parent().siblings(".name").text();
            var text;
            if (text1.substring(0, 3) == "沉积物") {
                text = text1.substring(4, text1.length);
            }
            else if (text1.substring(0, 4) == "浮游动物" || text1.substring(0, 4) == "浮游植物" || text1.substring(0, 4) == "底栖生物") {
                text = text1.substring(5, text1.length);
            }
            else if (text1.substring(0, 6) == "优势浮游动物" || text1.substring(0, 6) == "优势浮游植物" || text1.substring(0, 6) == "优势底栖生物") {
                text = text1.substring(7, text1.length);
            }
            $.ajax({
                type: "get",
                async: true,
                url: "DeleteMonit.action?monitID=" + text,
                success: function (result) {
                    if (result == "isnull") {
                        alert("删除失败，请检查数据库是否有该数据！");
                        return false;
                    } else if (result == "error") {
                        alert("删除失败，请稍后再试！");
                        return false;
                    } else if (result == "success") {
                        alert("删除成功！");
                        //删除表格行
                        $("#pfea tr").eq(index).remove();
                    }
                }
            });
        }
    });
//添加
    $("#add-surface-sed,#add-surface-zoo,#add-surface-phy,#add-surface-ben").unbind("click").bind("click", function () {
        $(".submit").show();
        $(".alter").hide();
        //清除前一次验证的错误信息
        $(".modal-form input").each(function () {
            $(this).val("").removeClass("error");
        });
        $("#feature_check").data('validator').resetForm();

        var text1 = tree.jstree().get_text(selected);
        var text;
        if (text1.substring(0, 3) == "监测点" || text1.substring(0, 2) == "断面") {
            text = tree.jstree().get_node(selected).id;
        }
        else if (text1.substring(0, 3) == "沉积物") {
            text = text1.substring(4, text1.length);
        }
        else if (text1.substring(0, 4) == "浮游动物" || text1.substring(0, 4) == "浮游植物" || text1.substring(0, 4) == "底栖生物") {
            text = text1.substring(5, text1.length);
        }
        else if (text1.substring(0, 6) == "优势浮游动物" || text1.substring(0, 6) == "优势浮游植物" || text1.substring(0, 6) == "优势底栖生物") {
            text = text1.substring(7, text1.length);
        }
        if (text.substring(0, 3) == "SEC" && $.trim($(this).text()) == "添加沉积物") {
            $.ajax({								//查询是否有沉积物，如果有则无法再次插入
                type: "post",
                async: true,
                url: "AddSediment.action",
                data: {
                    "flag": "query",
                    "ID_FractureSurface": text
                },

                success: function (result) {
                    if (result == "enough") {
                        alert("已经添加了沉积物");
                    }
                    else {
                        $(".title").text("添加沉积物");
                        $("#modal-sediment").show();
                    }
                }
            });

        } else if (text.substring(0, 3) == "SEC" && $.trim($(this).text()) == "添加浮游动物") {
            $.ajax({								//查询是否有浮游动物，如果有则无法再次插入
                type: "post",
                async: true,
                url: "AddZooPlankton.action",
                data: {
                    "flag": "query",
                    "ID_FractureSurface": text
                },

                success: function (result) {
                    if (result == "enough") {
                        alert("已经添加了浮游动物");
                    }
                    else {
                        $(".title").text("添加浮游动物");
                        $("#modal-feature").show();
                    }
                }
            });

        } else if (text.substring(0, 3) == "SEC" && $.trim($(this).text()) == "添加浮游植物") {
            $.ajax({								//查询是否有浮游植物，如果有则无法再次插入
                type: "post",
                async: true,
                url: "AddPhytoPlankton.action",
                data: {
                    "flag": "query",
                    "ID_FractureSurface": text
                },

                success: function (result) {
                    if (result == "enough") {
                        alert("已经添加了浮游植物");
                    }
                    else {
                        $(".title").text("添加浮游植物");
                        $("#modal-feature").show();
                    }
                }
            });
        }
        else if (text.substring(0, 3) == "SEC" && $.trim($(this).text()) == "添加底栖生物") {
            $.ajax({								//查询是否有底栖生物，如果有则无法再次插入
                type: "post",
                async: true,
                url: "AddBenthos.action",
                data: {
                    "flag": "query",
                    "ID_FractureSurface": text
                },

                success: function (result) {
                    if (result == "enough") {
                        alert("已经添加了底栖生物");
                    }
                    else {
                        $(".title").text("添加底栖生物");
                        $("#modal-feature").show();
                    }
                }
            });
        }

        var content = $(this).text();
        $(".submit").unbind("click").bind("click", function () {
            if (text.substring(0, 3) == "SEC" && $.trim(content) == "添加沉积物") {
                var formData = new FormData($("#form-sediment")[0]);
                //alert(formData);
                var url = "AddSediment.action";
                formData.append("flag", "insert");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#sediment-Photo").val().length > 100 || $("#sediment-Photo").val().length <= 0) formData.append("isNull", "");
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            alert("添加成功！");
                            $("#sed-fea tr:eq(0)").after(
                                "<tr><td id='left' class='name'>" + "沉积物:" + result + "</td>" +
                                "<td>无</td>" +
                                "<td>无</td>" +
                                "<td>" +
                                "<button id='showphoto'class='seephoto btn1 btn-primary'>查看</button>" +
                                "</td>" +
                                "<td>" +
                                "<button id='alter'class='update btn1 btn-primary'>修改</button>" +
                                "&nbsp;<button id='delete'class='delete btn1 btn-danger'>删除</button>" +
                                "</td>" +
                                "<td>无</td></tr>");
                            $(".modal").hide();
                        }
                    }
                });
            } else if (text.substring(0, 3) == "SEC" && $.trim(content) == "添加浮游动物") {
                if ($("#feature-Quality").val() == "") {
                    $("#feature-Quality").val("0")
                }
                if ($("#feature-Biomass").val() == "") {
                    $("#feature-Biomass").val("0")
                }
                var formData = new FormData($("#feature_check")[0]);
                var url = "AddZooPlankton.action";
                formData.append("flag", "insert");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#feature-Photo").val().length > 100 || $("#feature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            alert("添加成功！");
                            $("#sed-fea").append(
                                "<tr>" +
                                "<td id='left' class='name'>" + "浮游动物:" + result + "</td>" +
                                "<td>" + $("#feature-Biomass").val() + "</td>" +
                                "<td>" + $("#feature-Quality").val() + "</td>" +
                                "<td>" +
                                "<button id='showphoto'class='seephoto btn1 btn-primary'>查看</button>" +
                                "</td>" +
                                "<td>" +
                                "<button id='alter'class='update btn1 btn-primary'>修改</button>" +
                                "&nbsp;<button id='delete'class='delete btn1 btn-danger'>删除</button>" +
                                "</td>" +
                                "<td>" +
                                "<button class='btn1 btn-primary see'>查看</button>" +
                                "</td>" +
                                "</tr>");
                            $(".modal").hide();
                        }
                    }
                });
            } else if (text.substring(0, 3) == "SEC" && $.trim(content) == "添加浮游植物") {
                if ($("#feature-Quality").val() == "") {
                    $("#feature-Quality").val("0")
                }
                if ($("#feature-Biomass").val() == "") {
                    $("#feature-Biomass").val("0")
                }
                var formData = new FormData($("#feature_check")[0]);
                var url = "AddPhytoPlankton.action";
                formData.append("flag", "insert");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#feature-Photo").val().length > 100 || $("#feature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            alert("添加成功！");
                            $("#sed-fea").append(
                                "<tr>" +
                                "<td id='left' class='name'>" + "浮游植物:" + result + "</td>" +
                                "<td>" + $("#feature-Biomass").val() + "</td>" +
                                "<td>" + $("#feature-Quality").val() + "</td>" +
                                "<td>" +
                                "<button id='showphoto'class='seephoto btn1 btn-primary'>查看</button>" +
                                "</td>" +
                                "<td>" +
                                "<button id='alter'class='update btn1 btn-primary'>修改</button>" +
                                "&nbsp;<button id='delete'class='delete btn1 btn-danger'>删除</button>" +
                                "</td>" +
                                "<td>" +
                                "<button class='btn1 btn-primary see'>查看</button>" +
                                "</td>" +
                                "</tr>");
                            $(".modal").hide();
                        }
                    }
                });
            } else if (text.substring(0, 3) == "SEC" && $.trim(content) == "添加底栖生物") {
                if ($("#feature-Quality").val() == "") {
                    $("#feature-Quality").val("0")
                }
                if ($("#feature-Biomass").val() == "") {
                    $("#feature-Biomass").val("0")
                }
                var formData = new FormData($("#feature_check")[0]);
                var url = "AddBenthos.action";
                formData.append("flag", "insert");
                formData.append("FatherText", text);
                //alert(formData);
                if ($("#feature-Photo").val().length > 100 || $("#feature-Photo").val().length <= 0) {
                    formData.append("isNull", "");
                }
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            alert("添加成功！");
                            $("#sed-fea").append(
                                "<tr>" +
                                "<td id='left' class='name'>" + "底栖生物:" + result + "</td>" +
                                "<td>" + $("#feature-Biomass").val() + "</td>" +
                                "<td>" + $("#feature-Quality").val() + "</td>" +
                                "<td>" +
                                "<button id='showphoto'class='seephoto btn1 btn-primary'>查看</button>" +
                                "</td>" +
                                "<td>" +
                                "<button id='alter'class='update btn1 btn-primary'>修改</button>" +
                                "&nbsp;<button id='delete'class='delete btn1 btn-danger'>删除</button>" +
                                "</td>" +
                                "<td>" +
                                "<button class='btn1 btn-primary see'>查看</button>" +
                                "</td>" +
                                "</tr>");
                            $(".modal").hide();
                        }
                    }
                });
            }
        });
    });
//<---------------------孙梦海增加------------------>


    //添加子节点
    $("#add-child-node").unbind("click").bind("click", function () {
        $("#add-feature").css({"display": "none"});
        $("#rename-place").css({"display": "none"});
        $("#input-place").css({"display": "block"});
        $("#update-data").css({"display": "none"});

//	  设置默认省市县区位湖北省武汉市洪山区
        $("#province").find("option:selected").text("湖北省");
        $("#city").find("option:selected").text("武汉市");
        $("#area").find("option:selected").text("洪山区");
        $("#Site1").val("");

        $("#province,#city,#area").attr("disabled", false);
        $("#province,#city,#area").css('backgroundColor', '#fff');

//	  显示图片上传,隐藏查看照片按钮
        $("#Photo1,#tag").show();
        $("#monitsiteButton").hide();
        var text1 = tree.jstree().get_text(selected);
        var text;
        if (text1.substring(0, 3) == "监测点") {
            text = tree.jstree().get_node(selected).id;
        }
        else if (text1.substring(0, 2) == "断面") {
            text = tree.jstree().get_node(selected).id;
        }
        else if (text1.substring(0, 2) == "测线" || text1.substring(0, 2) == "测点") {
            text = text1.substring(3, text1.length);
        }
        else if (text1.substring(0, 4) == "采样水层") {
            text = text1.substring(5, text1.length);
        }
        function getAllNode(text) {
            $.ajax({
                type: "get",
                async: false,
                url: "AllMonit.action?monitID=" + text,
                success: function (result) {
                    if (result == "00") {
                        alert("发生错误，请稍后再试！");
                        return;
                    } else if (result == "" || result == null) {
                        alert("往后已无索引！");
                    } else {

                        MonitArr = result.split(',');
                        var str, icon;
                        if (text.substring(0, 3) == "MON") {
                            str = "断面:";
                            icon = "fa fa-area-chart";
                            tree.jstree().delete_node(MonitArr);
                            for (var ix = 0; ix < MonitArr.length; ix++) {
                                $.ajax({
                                    type: "get",
                                    url: "ShowMessage.action?monitID=" + MonitArr[ix],
                                    async: false,
                                    success: function (result) {
                                        MonitArrCon = result.split(',');
                                        tree.jstree().create_node(selected,
                                            {
                                                "id": MonitArrCon[0],
                                                "text": "断面:" + MonitArrCon[1],
                                                "icon": icon,
                                            }, "last");
                                        tree.jstree().open_node(selected);
                                    }
                                });
                            }
                        }
                        else {
                            if (text.substring(0, 3) == "SEC") {
                                str = "测线:";
                                icon = "fa fa-bar-chart-o";
                            }
                            else if (text.substring(0, 3) == "LIN") {
                                str = "测点:";
                                icon = "fa fa-dot-circle-o";
                            }
                            else if (text.substring(0, 3) == "PNT") {
                                str = "采样水层";
                                icon = "fa fa-circle-o";
                            }
                            else if (text.substring(0, 3) == "WLE") return;
                            //先删除所有节点，避免重复生成节点
                            tree.jstree().delete_node(MonitArr);

                            for (var ix = 0; ix < MonitArr.length; ix++) {
                                tree.jstree().create_node(selected,
                                    {
                                        "id": MonitArr[ix],
                                        "text": str + MonitArr[ix],
                                        "icon": icon,
                                    }, "last");
                            }
                        }
                    }
                }
            });
        }

        if (selected == "jh") {
            $("#add-monitsite").css({"display": "block"});
            $("#add-surface").css({"display": "none"});
            $("#add-line").css({"display": "none"});
            $("#add-Dot").css({"display": "none"});
            $("#add-water").css({"display": "none"});
            $("#add-child-sub").css({"display": "block"});
            $("#add-monitsite input").each(function () {
                $(this).val("");
            });
            // 天气下拉框恢复默认值
            $("#Weather1").val("晴");

        } else if (text.substring(0, 3) == "MON") {
            $("#add-monitsite").css({"display": "none"});
            $("#add-surface").css({"display": "block"});
            $("#add-line").css({"display": "none"});
            $("#add-Dot").css({"display": "none"});
            $("#add-water").css({"display": "none"});
            $("#add-child-sub").css({"display": "block"});
            $("#add-surface input").each(function () {
                $(this).val("");
            });
            // 采样方位下拉框恢复默认值
            $("#selectSurface").val("左岸");
        } else if (text.substring(0, 3) == "SEC") {
            $("#add-monitsite").css({"display": "none"});
            $("#add-surface").css({"display": "none"});
            $("#add-line").css({"display": "block"});
            $("#add-Dot").css({"display": "none"});
            $("#add-water").css({"display": "none"});
            $("#add-child-sub").css({"display": "block"});
            $("#add-line input").each(function () {
                $(this).val("");
            });

        } else if (text.substring(0, 3) == "LIN") {
            $("#add-monitsite").css({"display": "none"});
            $("#add-surface").css({"display": "none"});
            $("#add-line").css({"display": "none"});
            $("#add-Dot").css({"display": "block"});
            $("#add-water").css({"display": "none"});
            $("#add-child-sub").css({"display": "block"}); //增加节点的时候的确定按钮
            $("#add-Dot input").each(function () {
                $(this).val("");
            });
        } else if (text.substring(0, 3) == "PNT") {
            $.ajax({									//查询已有几个采样水层
                type: "post",
                async: true,
                url: "op_watlay.action",
                data: {
                    "flag": "query",
                    "ID_MeasuringPoint": text
                },
                success: function (result) {
                    if (result == "enough") {
                        alert("已经添加了三个采样水层");
                        $("#add-water").css({"display": "none"});
                        $("#add-child-sub").css({"display": "none"});
                    }
                }
            });
            $(".update-data").hide();
            $(".hand").show();

            $("#add-monitsite").css({"display": "none"});
            $("#add-surface").css({"display": "none"});
            $("#add-line").css({"display": "none"});
            $("#add-Dot").css({"display": "none"});
            $("#add-water").css({"display": "block"});
            $("#add-child-sub").css({"display": "block"}); //增加节点的时候的确定按钮
            $("#add-water input").each(function () {
                $(this).val("");
            });
        }
        $("#add-child-sub,.hand").unbind("click").bind("click", function () {
            //增加监测点
            if (selected == "jh") {
                var formData = new FormData($("#monitsite_check")[0]);
                var url = "op_monsite.action";
                formData.append("flag", "insert");
                formData.append("Site", $("#province").find("option:selected").text() + "-" + $("#city").find("option:selected").text() + "-" + $("#area").find("option:selected").text() + "-" + $("#Site1").val());
                if ($("#Photo1").val().length > 100 || $("#Photo1").val().length <= 0) formData.append("isNull", "");
                else formData.append("isNull", "有");
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: formData,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: "text",
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else if (result == "null") {
                            alert("请填写必填项！");
                        }
                        else {
                            $.ajax({
                                type: "get",
                                url: "ShowMessage.action?monitID=" + result,
                                async: false,
                                success: function (result) {
                                    MonitArrCon = result.split(',');
                                    tree.jstree().create_node(selected,
                                        {
                                            "id": MonitArrCon[0],
                                            "text": "监测点:" + MonitArrCon[5] + " " + MonitArrCon[4].split("-")[3] + " " + MonitArrCon[0].substring(3, 11),
                                            "icon": "fa fa-bank",
                                        }, "last");
                                }

                            });
                            //添加新节点跳到新节点
                            tree.jstree().deselect_node(selected);
                            //自动触发一次单击树节点事件
                            $(tree.jstree().select_node(result)).click();

                            alert("添加成功！");
                        }
                    }

                });

            } else if (text.substring(0, 3) == "MON") {

                //添加断面
                $.ajax({
                    type: "post",
                    async: true,
                    url: "op_frasur.action",
                    data: {
                        "flag": "insert",
                        "ID_MonitoringSite": text,					//外键
                        "Position": $("#selectSurface option:selected").text(),
                        "Distance2Bank": $("#Distance2Bank2").val()
                    },
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            getAllNode(text);
                            tree.jstree().open_node(selected);
                            //添加新节点跳到新节点
                            tree.jstree().deselect_node(selected);
                            //自动触发一次单击树节点事件
                            $(tree.jstree().select_node(result)).click();

                            alert("添加成功！");
                            $("#add-surface input").each(function () {
                                $(this).val("");

                            });
                        }
                    }
                });
            } else if (text.substring(0, 3) == "SEC") {				//添加测线
                $.ajax({
                    type: "post",
                    async: true,
                    url: "op_mealin.action",
                    data: {
                        "flag": "insert",
                        "ID_FractureSurface": text,				//外键
                        "StartLongitude": $("#StartLongitude3").val(),
                        "StartLatitude": $("#StartLatitude3").val(),
                        "EndLongitude": $("#EndLongitude3").val(),
                        "EndLatitude": $("#EndLatitude3").val()
                    },
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else if (result === "enough") {
                            alert("添加失败！已添加了三条测线");
                        } else {
                            getAllNode(text);
                            tree.jstree().open_node(selected);
                            //添加新节点跳到新节点
                            tree.jstree().deselect_node(selected);
                            //自动触发一次单击树节点事件
                            $(tree.jstree().select_node(result)).click();
                            alert("添加成功！");
                            $("#add-line input").each(function () {
                                $(this).val("");

                            });
                        }
                    }
                });
            } else if (text.substring(0, 3) == "LIN") {				//添加测点
                $.ajax({
                    type: "post",
                    async: true,
                    url: "op_meapoi.action",
                    data: {
                        "flag": "insert",
                        "ID_MeasuringLine": text,				//外键
                        "Longitude": $("#LongitudeDot").val(),
                        "Latitude": $("#LatitudeDot").val(),
                    },
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            getAllNode(text);
                            tree.jstree().open_node(selected);
                            //添加新节点跳到新节点
                            tree.jstree().deselect_node(selected);
                            //自动触发一次单击树节点事件
                            $(tree.jstree().select_node(result)).click();

                            alert("添加成功！");
                            $("#add-line input").each(function () {
                                $(this).val("");
                            });
                        }
                    }
                });

            } else {
                $.ajax({								//添加采样水层
                    type: "post",
                    async: true,
                    url: "op_watlay.action",
                    data: {
                        "flag": "insert",
                        "ID_MeasuringPoint": text,				//外键
                        //"Number":$("#Number").val(),
                        "Layer": $("#selectWater option:selected").text(),
                        "Depth": $("#Depath").val(),
                        "Temperature": $("#waterWarm").val(),
                        "WaterLevel": $("#waterHeight").val(),
                        "Velocity": $("#waterFlow").val()
                    },
                    success: function (result) {
                        if (result == "error") {
                            alert("添加失败！");
                        } else {
                            tree.jstree().create_node(selected,
                                {
                                    "id": result,
                                    "text": "采样水层:" + result,
                                    "icon": "fa fa-circle-o",
                                }, "last");
                            alert("添加成功！");
                            $("#add-line input").each(function () {
                                $(this).val("");

                            });
                        }
                    }
                });

            }

        });

    });


    //删除节点
    $("#delete-node").unbind("click").bind("click", function () {

        if (selected == "jh") {
            alert("该根节点不能删除！");
            return;
        }

        if (choosed.selected.length>1) {
            if (confirm("确定删除这些数据吗?")) {
                multiDelete();
                return;
            }
            return;
        }

        if (confirm("您确定删除该条数据吗？")) {
            $("#input-place").css({"display": "none"});
            $("#rename-place").css({"display": "none"});
            var text1 = tree.jstree().get_text(selected);

            var mon = text1.split(':');
            var text = mon[1];
            if (text1.substring(0, 3) == "监测点" || text1.substring(0, 2) == "断面") {
                text = tree.jstree().get_node(selected).id;
            }

            $.ajax({
                type: "get",
                async: true,
                url: "DeleteMonit.action?monitID=" + text,
                success: function (result) {
                    if (result == "isnull") {
                        alert("删除失败，请检查数据库是否有该数据！");
                        return false;
                    } else if (result == "error") {
                        alert("删除失败，请稍后再试！");
                        return false;
                    } else if (result == "success") {
                        var parent = tree.jstree().get_parent(selected);
                        tree.jstree().delete_node(selected);
                        //自动触发一次单击树节点事件
                        tree.jstree().select_node(parent).click();

                        alert("删除成功！");
                        $("#input-place").css({"display": "none"});
                        $("#rename-place").css({"display": "none"});
                        $("#tree-menu").css({"display": "none"});
                    }
                }
            });
        }
    });

    var name;
    var buttonID;
    $("#closeWLE").click(function () {
        $("#showWLE").css({"display": "none"});
    });
    $(document).on("click", "#addWLEupper,#addWLEmiddle,#addWLElow,#addWLEmix", function () {
        buttonID = $(this).attr("ID");
        $("#showWLE input").each(function () {
            $(this).val("");
        });
        if (buttonID == "addWLEupper") {
            $(".title").text("添加采样水层（上）");
        }
        else if (buttonID == "addWLEmiddle") {
            $(".title").text("添加采样水层（中）");
        }
        else if (buttonID == "addWLElow") {
            $(".title").text("添加采样水层（下）");
        }
        else if (buttonID == "addWLEmix") {
            $(".title").text("添加混合采样水层");
        }

        $("#showWLE").css({"display": "block"});
        name = $(this).attr("ID");
    });

    $("#sumbitWLE").click(function () {

        var formData = new FormData($("#testWLE")[0]);
        var selectTable;
        var str;
        var layer;
        if ($(this).html() == "确认提交") {
            str = "添加";
            formData.append("flag", "insert");
            formData.append("ID_MeasuringPoint", idPNT);
            switch (name) {
                case "addWLEupper":
                    formData.append("Layer", "上");
                    layer = "上";
                    selectTable = "WLEupper";
                    break;
                case "addWLEmiddle":
                    formData.append("Layer", "中");
                    layer = "中";
                    selectTable = "WLEmiddle";
                    break;
                case "addWLElow":
                    formData.append("Layer", "下");
                    layer = "下";
                    selectTable = "WLElow";
                    break;
                case "addWLEmix":
                    formData.append("Layer", "混");
                    layer = "混";
                    selectTable = "WLEmix";
                    break;
            }
        }
        else {
            str = "修改";
            formData.append("flag", "update");
            switch (buttonID) {
                case "updateWLEupper":
                    formData.append("Layer", "上");
                    formData.append("ID", WLEID1);
                    selectTable = "WLEupper";
                    break;
                case "updateWLEmiddle":
                    formData.append("Layer", "中");
                    formData.append("ID", WLEID2);
                    selectTable = "WLEmiddle";
                    break;
                case "updateWLElow":
                    formData.append("Layer", "下");
                    ;
                    formData.append("ID", WLEID3);
                    selectTable = "WLElow";
                    break;
                case "updateWLEmix":
                    formData.append("Layer", "混");
                    ;
                    formData.append("ID", WLEID4);
                    selectTable = "WLEmix";
                    break;

            }

        }
        $.ajax({
                type: "post",
                async: true,
                url: "op_watlay.action",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    if (result == "error") {
                        alert(str + "失败！");
                    } else {
                        alert(str + "成功 ");
                        var data = [];
                        $("#showWLE input").each(function (i, n) {
                            data[i] = $(this).val();
                        });
                        if (str == "添加") {
                            $("#" + selectTable).show();
                            $("#add" + selectTable).hide();
                            $(".hideView").hide();
                            $("#testWLE input").each(function () {
                                $(this).val("");
                            });

                            $.ajax({
                                type: "get",
                                async: false,
                                url: "AllMonit.action?monitID=" + selected,
                                success: function (result) {
                                    if (result == "00") {
                                        alert("发生错误，请稍后再试！");
                                        return;
                                    } else if (result == "" || result == null) {
                                        alert("往后已无索引！");
                                    } else {

                                        MonitArr = result.split(',');
                                        //先删除所有节点，避免重复生成节点
//								  for(var ix = 0;ix<MonitArr.length;ix ++){
//									  var node=MonitArr[ix].substring(2);
//									  tree.jstree().delete_node(node);
//									  alert("1");
//								  }

//								  for(var ix = 0;ix<MonitArr.length;ix ++){
                                        tree.jstree().create_node(selected,
                                            {
                                                "id": MonitArr[MonitArr.length - 1].substring(2),
                                                "text": "采样水层" + MonitArr[MonitArr.length - 1],
                                                "icon": "fa fa-circle-o",
                                            }, "last");
//									}

                                    }
                                }
                            });
                            tree.jstree().open_node(selected);
                            //添加新节点跳到新节点
                            tree.jstree().deselect_node(selected);
                            //自动触发一次单击树节点事件
                            $(tree.jstree().select_node(result)).click();
                        }
                        $("#" + selectTable + " td").each(function (i, n) {
                            if (i > 3) return;
                            var st = data[i].split(".");
                            var da;
                            if (st[1] == null) {
                                da = st[0] + ".00";
                            } else if (st[1].length == 1) {
                                da = st[0] + "." + st[1] + "0";
                            } else {
                                da = data[i];
                            }
                            $(this).html(da);
                        });
                        $("#showWLE").css({"display": "none"});

                    }
                }

            }
        );
    });

    $(document).on("click", "#updateWLEupper,#updateWLEmiddle,#updateWLElow,#updateWLEmix", function () {
        buttonID = $(this).attr("ID");
        if (buttonID == "updateWLEupper") {
            $(".title").text("修改采样水层（上）");
        }
        else if (buttonID == "updateWLEmiddle") {
            $(".title").text("修改采样水层（中）");
        }
        else if (buttonID == "updateWLElow") {
            $(".title").text("修改采样水层（下）");
        }
        else if (buttonID == "updateWLEmix") {
            $(".title").text("修改混合采样水层");
        }

        $("#showWLE").css({"display": "block"});
        $("#sumbitWLE").html("确认修改");
        var da = [];
        $("#" + buttonID.substring(6, buttonID.length) + " td").each(function (i, n) {
            if (i > 3) return;
            da[i] = $(this).html();
        });
        $("#showWLE input").each(function (i, n) {
            $(this).val(da[i]);
        });
    });

});